Typical Usage:
Assume the bean name "BDLC1".
(1)
The first typical usage of this bean is communication using communication events.
Required bean settings:
- IFR Type: No IFR
EVENTS.C
void BDLC1_OnReceiveData(void)
{
byte Out[5];
word Size=5;
word Len;
BDLC1_RecvBlock(Out,Size,&Len); //Read received data
BDLC1_ClearRxBuf(); //Clear Rx buffer
BDLC1_SendBlock(Out,Len); //Send the data back
}
void BDLC1_OnTransmitData(void)
{
BDLC1_ClearRxBuf(); //Data transmitted, Clear Rx buffer
}
(2)
The second typical usage of this bean is communication using transmission with multiple bytes IFR (In-Frame Response).
The following example shows how to recognize a communication error using the method GetError.
Note: In interrupt communication mode you can use the OnError event to recognize an
error during communication.
Required bean settings:
- IFR Type: Multiple bytes with/without CRC from a single responder
MAIN.C
byte Flag;
BDLC1_TError error; //TError union is defined in the header file
byte Out[5];
byte ifr[3];
void main(void)
{
byte Len
.
.
.
Flag = 0; //Clear end of frame flag
BDLC1_SendBlock(Out,5); //Send data
while(!Flag) ; //Wait for Tx complete
BDLC1_GetError(&error); //Get errors
if(error.err == 0)
//No error
BDLC1_RecvIFR(ifr,3,&Len); //if no error, read IFR
else
if(err.errName.Arbitration)
//Arbitration error
else if(err.errName.Framing)
//Framing error
.
.
.
BDLC1_ClearRxBuf();
BDLC1_ClearIFRbuf();
.
.
.
}
EVENTS.C
extern byte TxFlag;
void BDLC1_OnTransmitData(void)
{
Flag |= 1; //Indicate end of frame
}
void BDLC1_OnReceiveData(void)
{
Flag |= 2; //Indicate end of frame
}
For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.
|